package com.app.core.presenter;


import android.text.TextUtils;

import com.yanzhenjie.httpmodule.http.CallServer;
import com.yanzhenjie.httpmodule.http.Result;
import com.yanzhenjie.httpmodule.http.StringRequest;
import com.yanzhenjie.nohttp.Logger;
import com.yanzhenjie.nohttp.rest.Response;
import com.yanzhenjie.nohttp.rest.SimpleResponseListener;

/**
 * @author zhanghao
 * @ClassName: ParseDataImpl
 * @Description: 网络请求数据通用请求实现类
 * @date 2016年4月26日 下午2:47:49
 */
public class ParseDataImpl implements ParseData{

    protected static final String TAG = "ParseDataImpl";
    @Override
    public void commonRequest(final DataCallback dataCallback, int what, StringRequest request) {
        CallServer.getInstance().request(what, request, new SimpleResponseListener<Result<String>>() {
            @Override
            public void onSucceed(int what, Response<Result<String>> response) {
                super.onSucceed(what, response);
                String result = response.get().getResult();
                Logger.e("result:"+result);
                if (!TextUtils.isEmpty(result)){
                    dataCallback.handleData(what,result);
                }

            }

            @Override
            public void onFailed(int what, Response<Result<String>> response) {
                super.onFailed(what, response);
                String msg = response.get().getError();
                Logger.e("msg:"+msg);
                if (!TextUtils.isEmpty(msg)){
                    dataCallback.handleErrorMessage(what,msg);
                }
            }
        });

    }
}
